package reflect;

import reflect.annotations.AutoRunMethod;

import java.lang.reflect.Method;

/**
 * 反射机制访问注解参数
 */
public class ReflectDemo8 {
    public static void main(String[] args) throws Exception {
        /*
        获取Person类中sayHello方法上注解@AutoRunMethod中的参数值
         */
        Class cls = Class.forName("reflect.Person");
        Method method = cls.getDeclaredMethod("sayHi");
        if (method.isAnnotationPresent(AutoRunMethod.class)) {
            AutoRunMethod arm = method.getAnnotation(AutoRunMethod.class);
            int value = arm.value();
            System.out.println("参数的value值为："+value);
        }

    }
}
